# config.nu
#
# Installed by:
# version = "0.102.0"
#
# This file is used to override default Nushell settings, define
# (or import) custom commands, or run any other startup tasks.
# See https://www.nushell.sh/book/configuration.html
#
# This file is loaded after env.nu and before login.nu
#
# You can open this file in your default editor using:
# config nu
#
# See `help config nu` for more options
#
# You can remove these comments if you want or leave
# them for future reference.

$env.config = {
    show_banner: short
}

############################
#                          #
#          Prompt          #
#                          #
############################
def get_git_status [] {
    if (do { git rev-parse --is-inside-work-tree } | complete).exit_code == 0 {
        let branch = (git branch --show-current | str trim)
        let has_changes = (git status --porcelain | str trim | str length) > 0
        
        if $has_changes {
            $"| (ansi ri)git:($branch)(ansi reset)❗"
        } else {
            $"| (ansi ui)git:($branch)(ansi reset)"
        }
    } else { "" }
}

def convert_windows_path [] {
    let path = $in | str replace -a '\' '/'
    if ($path | parse -r '^([A-Za-z]):' | is-empty) {
        $path
    } else {
        let drive = ($path | parse -r '^([A-Za-z]):' | get capture0.0 | str downcase)
        $"/($drive)($path | str replace -r '^[A-Za-z]:' '')"
    }
}

def create_left_prompt [] {
    let path = ($env.PWD 
        | str replace $"($env.HOME | path expand)" "~"
        | convert_windows_path
    )
    $"(ansi green)($path)(ansi reset) (get_git_status)\n "
}

$env.PROMPT_COMMAND = { create_left_prompt }

############################
#                          #
#          Common          #
#                          #
############################
alias ari = aria2c -x 16
alias cdd = cd E:\Desktop
alias cod = code
alias l = ls
alias ll = ls
alias mk = mkdir
alias proxy_on = load-env {'HTTP_PROXY': '127.0.0.1:7890', 'HTTPS_PROXY': '127.0.0.1:7890'}
alias proxy_off = hide-env 'HTTP_PROXY'; hide 'HTTPS_PROXY'
alias tree = tree /f

############################
#                          #
#          Docker          #
#                          #
############################
alias dis = docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"
alias dps = docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
alias dr = docker run -dit --gpus all --net=host -w /root/workspace 
def de [container] {
    docker exec -it $container bash
}

############################
#                          #
#          Python          #
#                          #
############################
alias pii = pip install -U
alias pl = pip list
alias pu = pip install --upgrade
def pg [name] {
    pip list | find $name
}
